home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
Sherlock 2.0
/
DevLibSrc
/
Main_DevLib
/
LIBend.c
< prev
next >
Wrap
Text File
|
1996-02-09
|
2KB
|
137 lines
/*
devlib: General program termination module.
source: LIBend.c
started: November 4, 1993.
version:
October 26, 1995.
Call w_applEvent in end_wait_for_exit only if USE_MAC_TOOLBOX not defined.
September 25, 1995.
Added support for Code Warrior.
January 7, 1994.
*/
#include "LIBlib.h"
#include "LIBend.h"
#include <LIBlog.h>
#include <LIBos.h>
#if defined(THINK_C) || defined(SYMANTEC_C) || defined(__MWERKS__)
#include <Mac_gui.h>
#endif
#include <stdlib.h> /* for _exitting(). */
/*
Forward declarations of internal routines.
*/
static void end_wait_for_exit (char * message);
static void undo_interrupts (void);
/*
A signigicant system error has occured.
Wait for the user to choose quit so that the error message is sure
to be seen, then close all files and exit.
*/
void
end_abort(void)
{
end_wait_for_exit("\nChoose quit (or command q) immediately!\n");
end_close_all();
log_close();
undo_interrupts();
abort();
}
/*
The program is finished: Exit after waiting for quit or a keystroke.
*/
void
end_done(void)
{
end_wait_for_exit("\nChoose quit (or command q) to exit.\n");
end_close_all();
log_close();
undo_interrupts();
exit(0);
}
/*
Quit has been chosen: close all files and exit immediately.
*/
void
end_quit(void)
{
ecnls(2); es(lib_program_name); es(" terminated by user.\n");
end_close_all();
main_quit();
log_close();
undo_interrupts();
exit(0);
}
/*
There has been an argument error. Wait for the user to choose quit.
*/
void
end_usage(void)
{
end_wait_for_exit("\nChoose quit (or command q) now.\n");
end_close_all();
log_close();
undo_interrupts();
exit(0);
}
/*
Wait for the user to choose quit or hit a key.
*/
static void
end_wait_for_exit(char * message)
{
static int abort_flag = FALSE;
#if defined(THINK_C) || defined(SYMANTEC_C) || defined(__MWERKS__)
es(message);
/* Make sure we call end_wait_for_exit at most once. */
if (!abort_flag) {
abort_flag = TRUE;
/*
Wait for quit to be chosen.
Don't call w_applEvent if we are using the console package!
*/
#ifndef USE_MAC_TOOLBOX
while(w_applEvent(0) == TRUE) {
;
}
#endif
}
#endif
}
static void
undo_interrupts(void)
{
#ifdef THINK_C
#if 0 // This appears not to work in version 7 of Think C.
/*
_exiting(1) call all installed shutdown routines.
_exiting(0) call only routines installed with "_atexit."
*/
_exiting(0);
#endif
#endif
}